﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FTBS.Models.DAO;
using FTBS.Models.Entities;

namespace FTBS.Models.BLO
{
    public class PromotionBLO
    {
        private PromotionDAO _promotionDao = new PromotionDAO();

        /// <summary>
        /// Validate FromDate and ToDate
        /// </summary>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        /// <returns>0: Validate -- 1: ToDate smaller than FromDate -- 2: toDate smaller than ToDay -- 3: fromDate smaller than ToDay</returns>
        public int IsValidateFromAndToDate(DateTime fromDate, DateTime toDate)
        {
            int result = 0;
            if (toDate < fromDate)
            {
                result = 1;
            }
            if (fromDate < toDate)
            {
                if (toDate < DateTime.Today)
                {
                    result = 2;
                }
                if (fromDate < DateTime.Today)
                {
                    result = 3;
                }
            }
            return result;
        }

        /// <summary>
        /// get list of promotions
        /// </summary>
        /// <returns>List of promotions</returns>
        /// <author>hungph</author>
        public List<Promotion> LoadAllPromotions()
        {
            var listPro = _promotionDao.GetAllPromotions();
            return listPro;
        }

        /// <summary>
        /// Get list promotion for Create Schedule
        /// Get All promotion have FromDate > Today
        /// </summary>
        /// <returns>List of Promotion have FromDate >= Today</returns>
        /// <author>VuongVT</author>
        public List<Promotion> GetListPromotionForCreateSchedule()
        {
            return _promotionDao.GetListPromotionForCreateSchedule();
        }

        /// <summary>
        /// load Promotions Order By Id
        /// </summary>
        /// <returns>List of promotions</returns>
        /// <author>hungph</author>
        public List<Promotion> LoadPromotionsOrderById()
        {
            var listPro = _promotionDao.LoadPromotionsOrderById();
            return listPro;
        }
        /// <summary>
        /// Select promotion by schedule
        /// </summary>
        /// <param name="schedule"></param>
        /// <returns></returns>
        public Promotion GetPromotionByScheduleId(Schedule schedule)
        {
            return _promotionDao.GetPromotionByScheduleId(schedule);
        }

        /// <summary>
        /// get a Promotion by ID
        /// </summary>
        /// <returns>Promotion</returns>
        /// <author>hungph</author>
        public Promotion LoadPromotionById(int id)
        {
            var promotion = _promotionDao.LoadPromotionById(id);
            return promotion;
        }

        /// <summary>
        /// create a new promotion
        /// </summary>
        /// <returns>bool</returns>
        /// <author>hungph</author>
        public bool CreatePromotion(Promotion promotion)
        {
            var result = _promotionDao.Add(promotion);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Edit promotion 
        /// </summary>
        /// <returns>bool</returns>
        /// <author>hungph</author>
        public bool EditPromotion(Promotion promotion)
        {
            var result = _promotionDao.Edit(promotion);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// delete promotion
        /// </summary>
        /// <returns>bool</returns>
        /// <author>hungph</author>
        public bool DeletePromotion(Promotion promotion)
        {
            var result = _promotionDao.Delete(promotion);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Check if promotion name is existed or not when create
        /// </summary>
        /// <param name="promotion"></param>
        /// <returns>true || false</returns>
        /// <author>hungph</author>
        /// <date>3/7/2014</date>
        public bool CheckIsExistedCreate(Promotion promotion)
        {
            return _promotionDao.CheckIsExistedCreate(promotion);
        }

        /// <summary>
        /// Check is exist the promotion name when update
        /// </summary>
        /// <param name="promotion"></param>
        /// <returns>True: Existed - False: Not existed</returns>
        /// <author>VuongVT</author>
        public bool CheckIsExistedEdit(Promotion promotion)
        {
            return _promotionDao.CheckIsExistedEdit(promotion);
        }

        public Promotion GetPromotionById(int id)
        {
            var promotion = _promotionDao.GetPromotionById(id);
            return promotion;
        }

        /// <summary>
        /// Check the ShowTimeId is used in Schedule and have Booked ticket or not
        /// This function is used for user Click to Edit in List Promotion
        /// </summary>
        /// <param name="showTimeId"></param>
        /// <returns>True: Is Exist ---- False: Not Exist</returns>
        /// <author>VuongVT</author>
        public bool IsPromotionUsedForScheduleAndBooked(int promotionId)
        {
            return _promotionDao.IsPromotionUsedForScheduleAndBooked(promotionId);
        }

        /// <summary>
        /// Check the ShowTimeId is used in Schedule or not
        /// This function is used for user Click to Delete in List Promotion
        /// </summary>
        /// <param name="showTimeId"></param>
        /// <returns>True: Is Exist ---- False: Not Exist</returns>
        /// <author>VuongVT</author>
        public bool IsPromotionUsedForSchedule(int promotionId)
        {
            return _promotionDao.IsPromotionUsedForSchedule(promotionId);
        }
    }
}